import cv2
import numpy as np

img = cv2.imread("./img/color_recognize2.png")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, binary = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY_INV)
blue = cv2.bitwise_and(img[:, :, 0], binary)
green = cv2.bitwise_and(img[:, :, 1], binary)
red = cv2.bitwise_and(img[:, :, 2], binary)

if np.sum(blue > 0) > 0:
    print("存在蓝色像素")
if np.sum(green > 0) > 0:
    print("存在绿色像素")
if np.sum(red > 0) > 0:
    print("存在红色像素")

# cv2.imshow("channel", blue)
# cv2.waitKey(0)
